package com.walkline.travelassistant.dao;

import java.util.Vector;

import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;

import com.walkline.travelassistant.TravelAssistantException;
import com.walkline.travelassistant.TravelAssistantSDK;
import com.walkline.travelassistant.inf.SuggestionItem;
import com.walkline.travelassistant.inf.SuggestionResult;
import com.walkline.util.Function;

public class TravelAssistantSuggestionResult extends TravelAssistantObject implements SuggestionResult
{
	private int _status = 0;
	private String _message = "";
	private Vector _result_list = new Vector();
	private int _result_count = 0;

	public TravelAssistantSuggestionResult(TravelAssistantSDK travelAssistant, JSONObject jsonObject) throws TravelAssistantException
	{
		super(travelAssistant, jsonObject);

		JSONObject suggestionResultObject = jsonObject;
		if (suggestionResultObject != null)
		{
			_status = suggestionResultObject.optInt("status");
			_message = suggestionResultObject.optString("message");

			JSONArray resultsArray = suggestionResultObject.optJSONArray("result");
			if (resultsArray != null)
			{
				JSONObject resultObject;

				_result_count = resultsArray.length();
				for (int i=0; i<_result_count; i++)
				{
					try {
						resultObject = (JSONObject) resultsArray.get(i);

						SuggestionItem result = new TravelAssistantSuggestionItem(travelAssistant, resultObject);
						if (result != null) {_result_list.addElement(result);}
					} catch (JSONException e) {Function.errorDialog(e.toString());}
				}
			}
		}
	}

	public int getStatus() {return _status;}

	public String getMessage() {return _message;}

	public Vector getSuggestionResult() {return _result_list;}

	public int getSuggestionResultCount() {return _result_count;}
}